import request from "@/utils/request.js";

//登录
export const loginAPI = (data) => {
  return request({
    method: 'post',
    url: '/login',
    data
  })
}

//列表
export const roleListAPI = ({ pagenum, pagesize }) => {
  return request({
    method: 'get',
    url: '/users',
    params: {
      pagenum,
      pagesize
    }
  })
}

//角色列表
export const userListAPI = () => {
  return request.get('/roles')
}

//  获取-权限列表-扁平结构
export const purlistAPI = () => {
  return request.get('/rights/list')
}

//修改用户
export const editusertAPI = (obj) => {
  return request({
    method: 'put',
    url: '/users/' + obj.id,
    data: {
      email: obj.email,
      mobile: obj.mobile
    }
  })
}

//删除
export const delusertAPI = (id) => {
  return request({
    method: 'delete',
    url: '/users/' + id,
  })
}

//添加
export const addusertAPI = (obj) => {
  return request({
    method: 'post',
    url: '/users',
    data: {
      username: obj.username,
      password: obj.password,
      email: obj.email,
      mobil: obj.mobil,
    }
  })
}

//搜索
export const searchAPI = ({ pagenum, pagesize, query }) => {
  return request({
    method: 'get',
    url: '/users',
    params: {
      pagenum,
      pagesize,
      query
    }
  })
}

//用户状态
export const statusAPI = ({ id, bool }) => {
  return request({
    method: 'put',
    url: '/users/' + id + '/state/' + bool,
  })
}

//删除权限点
export const delqxAPI = (id, delid) => {
  return request.delete(`/roles/${id}/rights/${delid}`)
}

//权限列表
export const purviewListAPI = (id, delid) => {
  return request.get('/rights/tree')
}


//角色分配-权限点
export const purviewpointAPI = (roleId, idstr) => {
  return request.post(`/roles/${roleId}/rights`, { rids: idstr })
}